//
//  UserModel.m
//  WheatPlan
//
//  Created by 郑渊文 on 6/9/15.
//  Copyright (c) 2015 IOSTeam. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel

+(BOOL)propertyIsOptional:(NSString*)propertyName
{
    return YES;
}

-(instancetype)initWithDictionary:(NSDictionary *)dictionary{
    if (self = [super init]) {
        self.isNotLogin = [dictionary valueForKey:@"r"];
        NSDictionary *tempUserInfoDic = [dictionary valueForKey:@"user_info"];
        self.cookies = [tempUserInfoDic valueForKey:@"ck"];
        self.userId = [tempUserInfoDic valueForKey:@"id"];
//        self.name = [tempUserInfoDic valueForKey:@"name"];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.userId = [aDecoder decodeObjectForKey:@"userId"];
        self.resultCode = [aDecoder decodeObjectForKey:@"resultCode"];
        self.msg = [aDecoder decodeObjectForKey:@"msg"];
        self.dataList = [aDecoder decodeObjectForKey:@"dataList"];
        self.parentSchoolId = [aDecoder valueForKey:@"parentSchoolId"];

    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:_userId forKey:@"userId"];
    [aCoder encodeObject:_resultCode forKey:@"resultCode"];
    [aCoder encodeObject:_msg forKey:@"msg"];
    [aCoder encodeObject:_dataList forKey:@"dataList"];
    [aCoder encodeObject:_parentSchoolId forKey:@"parentSchoolId"];

}

- (void)archiverUserInfo{
    NSMutableData *data = [[NSMutableData alloc]init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
    [archiver encodeObject:self forKey:@"userInfo"];
    [archiver finishEncoding];
    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *appdelegatePath = [homePath stringByAppendingPathComponent:@"appdelegate.archiver"];
    //添加储存的文件名
    if ([data writeToFile:appdelegatePath atomically:YES]) {
        ////NSLog(@"UesrInfo存储成功");
    }
}
@end
